
DEFINE VARIABLE amt AS DECIMAL FORMAT ">>>>>>>>>>>>>9.99".
DEFINE VARIABLE f1 AS DECIMAL FORMAT ">9.99".
DEFINE VARIABLE d1 AS INTEGER.
DEFINE VARIABLE d2 AS INTEGER.
DEFINE VARIABLE str AS CHARACTER FORMAT "x(80)" .
DEFINE VARIABLE i AS INTEGER.

DEFINE VARIABLE w1 AS CHARACTER EXTENT 4.
DEFINE VARIABLE w2 AS CHARACTER EXTENT 20.
DEFINE VARIABLE w3 AS CHARACTER EXTENT 10.

FUNCTION conv-eng RETURNS CHARACTER (INPUT idx AS INTEGER, INPUT val AS INTEGER) FORWARD.

w1[1] = " ".
w1[2] = " thousand ".
w1[3] = " million ".
w1[4] = " billion ".

w2[1] = "one".
w2[2] = "two".
w2[3] = "three".
w2[4] = "four".
w2[5] = "five".
w2[6] = "six".
w2[7] = "seven".
w2[8] = "eight".
w2[9] = "nine".
w2[10] = "ten".
w2[11] = "eleven".
w2[12] = "twelve".
w2[13] = "thirteen".
w2[14] = "fourteen".
w2[15] = "fifteen".
w2[16] = "sixteen".
w2[17] = "seventeeb".
w2[18] = "eighteen".
w2[19] = "nineteen".
w2[20] = "twenty".

w3[1] = "".
w3[2] = "twenty".
w3[3] = "thirty".
w3[4] = "forty".
w3[5] = "fifty".
w3[6] = "sixty".
w3[7] = "seventy".
w3[8] = "eighty".
w3[9] = "ninety".

amt = 1035.89.

f1 = amt - TRUNCATE(amt,0).

IF f1 <> 0 THEN 
    str = "and " + STRING(100 * f1) + "/100 only".
ELSE
    str = "only".

d1 = TRUNCATE(amt,0).

DO i = 1 TO 3 :
    d2 = d1 MODULO 1000.
    d1 = INTEGER((d1 - d2) / 1000).
    str = conv-eng(i, d2) + str.
END.
    

MESSAGE str VIEW-AS ALERT-BOX.


FUNCTION conv-eng RETURNS CHARACTER (INPUT idx AS INTEGER, INPUT val AS INTEGER):

    DEFINE VARIABLE i1 AS INTEGER.
    DEFINE VARIABLE i2 AS INTEGER.

    IF val = 0 THEN 
        RETURN "".
    ELSE IF val <= 20 THEN
        RETURN w2[val] + w1[idx].
    ELSE IF val < 100 THEN
        RETURN "and " + w3[INTEGER(TRUNCATE(val / 10,0))] + " " + w2[val MODULO 10] + w1[idx].
    ELSE DO :
        i2 = val MODULO 100.
        i1 = INTEGER((val - i2) / 100).
        IF i2 = 0 THEN
            RETURN w2[i1] + " hundred" + w1[idx].
        ELSE IF i2 < 20 THEN
            RETURN w2[i1] + " hundred and " + w2[i2] + w1[idx].
        ELSE 
            RETURN w2[i1] + " hundred " + w3[INTEGER(TRUNCATE(i2 / 10,0))] + " " + w2[i2 MODULO 10] + w1[idx].
    END.

    RETURN "".

END FUNCTION.

